% This file analyzes the experiments intended to reveal the tensor monopole
% generates Fig2C

%% 3-form curvature from metric tensor
load('./data/Fig2A.mat')

alpha_fit=linspace(0,pi/2,41);

cc=[0.0549    0.2706    0.6275
    0.9020         0    0.0627
    0.0980    0.5412    0.1843
    0.9882    0.7098    0.0588];

% Topological charge
[QT,QT_err] = Herror_charge(alpha_sweep,H_berry_curvature, H_berry_err);
disp(['Q_T=',num2str(QT),' +- ',num2str(QT_err)])

figure
errorbar(alpha_sweep/pi*180,H_berry_curvature, H_berry_err,'d','MarkerSize',12,'LineWidth',2,'Color',cc(1,:))
hold on
plot(alpha_fit/pi*180,sin(2*alpha_fit)/2,'LineWidth',1.5,'Color',cc(1,:),'HandleVisibility','off')
hold off
box off
ylabel('H_{\alpha\beta\phi}');
xlabel('\alpha ({\circ})')
set(gca,'FontSize',18)
% ylim([-0.01,0.5]);xlim([0,90]);
set(gca,'XTick',[0:30:90])

%% 3-form curvature from Berry curvature/connection
load('./data/Fig2BS14.mat')
% Topological charge
[QT,QT_err] = Herror_charge(alpha_sweep,H_berry_curvature, H_berry_err);
disp(['Q_T=',num2str(QT),' +- ',num2str(QT_err)])

% figure
hold on
plot(alpha_fit/pi*180,H_munu_theory,'--','LineWidth',1.5,'Color',cc(2,:),'HandleVisibility','off');
errorbar(alpha_sweep/pi*180,H_berry_curvature,H_berry_err,'d','MarkerSize',12,'LineWidth',2,'Color',cc(2,:))
ylabel('H_{\alpha\beta\phi}')
xlabel('\alpha(\circ)')
xlim([0,90]);ylim([-0.01,0.6]);
set(gca,'XTick',[0:30:90]);
set(gca,'FontSize',18)

lgd=legend('from $g_{\mu\nu}$','from $\mathcal{F}_{\mu\nu}$');
% lgd=legend('Metric tensor experiment','Berry curvature experiment');
lgd.FontSize=18;
set(lgd,'Interpreter','latex','Location','best')



function [QT,QT_err] = Herror_charge(alpha_sweep,H_berry_curvature, H_berry_err)
% calculates the topological charge
% takes alpha_sweep which is not equidistant

QT=sum((H_berry_curvature(1:end-1)+H_berry_curvature(2:end)).*(alpha_sweep(2:end)-alpha_sweep(1:end-1)));

QT_err=sqrt(sum((H_berry_err(1:end-1).^2+H_berry_err(2:end).^2).*(alpha_sweep(2:end)-alpha_sweep(1:end-1)).^2));
end

